package spotGUI.utils;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.EtchedBorder;

import utils.SocialUserData;


public class SocialUserListCellRenderer implements ListCellRenderer {

	private Font font = new Font("Dialog", Font.ITALIC, 12);
	private Color color = Color.DARK_GRAY;
	
	
	
	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {

			return new SocialRendererComponent((SocialUserData)value, font, color);
	}
	
	
	public class SocialRendererComponent extends JPanel {
		
		private JLabel lblName;
		private JLabel personalMessage;
		private JLabel lblPhoto;
		

		public SocialRendererComponent (SocialUserData user, Font font, Color color) {
			
			setToolTipText(user.getPersonalMessage());
			
			GridBagLayout gridBagLayout = new GridBagLayout();
			gridBagLayout.columnWidths = new int[]{20, 67, 0, 0};
			gridBagLayout.rowHeights = new int[]{7, 0};
			gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
			gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
			setLayout(gridBagLayout);
			
			lblPhoto = new JLabel("");
			lblPhoto.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
			lblPhoto.setIcon(user.getPhoto());
			GridBagConstraints gbc_lblPhoto = new GridBagConstraints();
			gbc_lblPhoto.insets = new Insets(0, 0, 0, 5);
			gbc_lblPhoto.gridx = 0;
			gbc_lblPhoto.gridy = 0;
			add(lblPhoto, gbc_lblPhoto);
			
			lblName = new JLabel(user.getFirstName()+" "+user.getSurname());
			GridBagConstraints gbc_name = new GridBagConstraints();
			gbc_name.anchor = GridBagConstraints.WEST;
			gbc_name.insets = new Insets(0, 0, 0, 5);
			gbc_name.gridx = 1;
			gbc_name.gridy = 0;
			add(lblName, gbc_name);
			
			personalMessage = new JLabel(user.getPersonalMessage());
			personalMessage.setForeground(color);
			personalMessage.setFont(font);
			personalMessage.setOpaque(false);
			GridBagConstraints gbc_statusMessage = new GridBagConstraints();
			gbc_statusMessage.anchor = GridBagConstraints.WEST;
			gbc_statusMessage.gridx = 2;
			gbc_statusMessage.gridy = 0;
			add(personalMessage, gbc_statusMessage);



		}

	}
}
